package cn.acac.yygh.hosp.controller.api;

import cn.acac.yygh.hosp.result.Result;
import cn.acac.yygh.hosp.service.DepartmentService;
import cn.acac.yygh.hosp.utils.HttpRequestHelper;
import cn.acac.yygh.model.hosp.Department;
import cn.acac.yygh.result.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
@Api("第三方医院科室的相关操作")
public class ApiDepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 根据医院编号和科室编号删除科室信息
     * @return
     */
    @PostMapping("/department/remove")
    public Result removeDepartment(HttpServletRequest request){
        // 获取请求参数
        Map<String, Object> switchMap = HttpRequestHelper.switchMap(request.getParameterMap());
        // 进行秘钥验证
        departmentService.removeDepartment(switchMap);
        return Result.ok();
    }

    /**
     * 返回第三方医院科室的分页信息
     * @param request
     * @return
     */
    @PostMapping("/department/list")
    public Result<Page> list(HttpServletRequest request){
        // 获取信息
        Map<String, Object> map = HttpRequestHelper.switchMap(request.getParameterMap());
        Page<Department> page = departmentService.selectPage(map);
        return Result.ok(page);
    }

    /**
     * 保存第三方医院科室的信息
     * @param request
     * @return
     */
    @PostMapping("/saveDepartment")
    public Result<Department> saveDepartment(HttpServletRequest request){
        // 获取信息
        Map<String, Object> map = HttpRequestHelper.switchMap(request.getParameterMap());
        departmentService.saveDepartment(map);
        return Result.ok();
    }
}
